package basic;

import java.util.ArrayList;
//求一个数的全部因子
public class basic1492 {
    public int kthFactor(int n, int k) {
        int i = 1;
        ArrayList<Integer> factorList = new ArrayList<>();
        while (i <= n) {
            if (n % i == 0) {
                factorList.add(i);
            }
            i++;
        }
        if (k<=factorList.size()){
            return  factorList.get(k-1);
        }
        return -1;

    }

    public static void main(String[] args) {
        basic1492 basic1492 = new basic1492();
        System.out.println(basic1492.kthFactor(7, 2));

    }
}
